﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["xxnewsConnectionString"].ConnectionString;
    SqlConnection sqlcon;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["pn"] == ""||Session["pn"] ==null)
        {
            Response.Redirect("default.aspx");
        }
        if (!IsPostBack)
        {
            string sqlstr = "";
            if (Session["pn"].ToString() == "段领导")
            {
                sqlstr = "select ch_pwname,in_id FROM siteman2 WHERE (bm_leibie ='段领导') ORDER BY ch_px";
            }
            else
            {
                sqlstr = "select ch_pwname,in_id FROM siteman2 WHERE (ch_bumen = '" + Session["pn"].ToString() + "') ORDER BY ch_px";
            }
            //Response.Write(sqlstr);
            try
            {
                sqlcon = new SqlConnection(strCon);
                SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
                DataSet myds = new DataSet();
                //sqlcon.Open();
                myda.Fill(myds, "siteman2");
                id.DataSource = myds;
                id.DataBind();
            }
            catch (SqlException)
            {
                
                throw;
            }
            
        }
         //Response.Write(Session["pn"]+"//");
        mima.Focus();
        mima.Attributes.Add("onmouseover", "this.focus()");
        mima.Attributes.Add("onfocus", "this.select()");
        id.Attributes.Add("onchange", "mima.focus()");
        if (mima.Text != "")
        {
            try
            {
                string sqlstr1 = "select * from siteman2 where in_id='" + id.SelectedItem.Value + "' and ch_pwd='" + mima.Text + "'";
                //Response.Write(sqlstr);
                sqlcon = new SqlConnection(strCon);
                SqlDataAdapter myda1 = new SqlDataAdapter(sqlstr1, sqlcon);
                DataSet myds1 = new DataSet();
                //sqlcon.Open();
                myda1.Fill(myds1, "siteman1");
                if (myds1.Tables[0].Rows.Count == 0)
                {
                    Response.Write("<SCRIPT language=javascript>alert('密码错误！');</SCRIPT>");
                }
                else
                {
                    Session["pngeren"] = myds1.Tables[0].Rows[0]["ch_pwname"].ToString();
                    if (Session["lb"] != null)
                    {
                        if (Session["lb"].ToString() == "审批")
                        {                            
                            if (Session["pn"].ToString() == "供电技术科")
                            {
                                Response.Redirect("zhzx_shenpilist.aspx");
                            }
                            else if (Session["pn"].ToString() == "电力技术科")
                            {
                                Response.Redirect("zhzx_shenpilist.aspx");
                            }
                            else if (Session["pn"].ToString() == "设备科")
                            {
                                Response.Redirect("sbk_shenpilist.aspx");
                            }
                            else
                            {
                                Response.Redirect("cj_shenpilist.aspx");
                            }
                        }
                        else if (Session["lb"].ToString() == "受理")
                        {
                            Response.Redirect("clk_shoulilist.aspx");
                        }
                        else if (Session["lb"].ToString() == "管理")
                        {
                            Response.Redirect("clk_guanli.aspx");
                        }
                        else if (Session["lb"].ToString() == "发料")
                        {
                            Response.Redirect("clk_faliaolist.aspx");
                        }
                        else if (Session["lb"].ToString() == "签收")
                        {
                            Response.Redirect("bz_qianshoulist.aspx");
                        }
                        else
                        {
                            Response.Redirect("bz_jihuachakan.aspx");
                        }
                    }
                }
            }
            catch (SqlException)
            {
                
                throw;
            }
        }
    }
}
